﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DAO;
using DTO;

namespace Banking.Member
{
    public partial class frmChuyenKhoan : Form
    {
        int _maTKThe;
        TypeDemo _type;
        TaiKhoanThe tk;
        int maNVGD = 3;
        string TruSo="HCM";
        public frmChuyenKhoan(int maTKThe,TypeDemo type)
        {
            InitializeComponent();
            _maTKThe = maTKThe;
            _type = type;
        }

        private void frmChuyenKhoan_Load(object sender, EventArgs e)
        {
            LoadThongTinTK();
        }
        private void LoadThongTinTK()
        {
            tk = new TaiKhoanThe();
            tk = TaiKhoanTheDA.GetByID(_maTKThe);
            txtMaTKGui.Text = tk.MaTaiKhoanThe.ToString();
            txtSoDu.Text = tk.SoDu.ToString();
            DataTable dt = NganHangDA.GetAll();
            cmbNganHang.DataSource = dt;
            cmbNganHang.DisplayMember = "TenNganHang";
            cmbNganHang.ValueMember = "MaNganHang";
        }

        private void btnChuyenTien_Click(object sender, EventArgs e)
        {
            if (cmbNganHang.Text == "")
                cmbNganHang.SelectedIndex = -1;
            GiaoDich gd = new GiaoDich();
            gd.MaTKThe = _maTKThe;
            gd.MaLoaiGD = 2;//chuyen tien
            gd.NgayGD = DateTime.Today;
            gd.DiaChiGD = TruSo;
            gd.SoTienGD = float.Parse(txtSoTienGui.Text);
            gd.NoiDungGD = txtNoiDung.Text;
            gd.MaTKNhan = int.Parse(txtMaTKNhan.Text);
            gd.MaNVGD = maNVGD;
            if (cmbNganHang.Text == "")//chuyen tien trong cung NH
            {
                GiaoDichDA.ChuyenTienTrongNH(gd, _type.typeDemo);
            }
            else//chuyen tien ngoai NH
            {
                gd.MaNganHang = int.Parse(cmbNganHang.SelectedValue.ToString());
                GiaoDichDA.ChuyenTienNgoaiNH(gd, _type.typeDemo);
            }
            MessageBox.Show("Success");
        }
    }
}
